package com.atcjx.pojo.Query.Article;

import com.atcjx.pojo.IConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName ArticleDTO.java
 * @Description TODO
 * @createTime 2021年09月26日 18:34:00
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("文章查询的条件封装类")
public class ArticleQueryDTO  {
    @ApiModelProperty("封装查询文章的状态(多个请使用','分隔开)")
    private String status;
    @ApiModelProperty("封装查询文章的标签(多个请使用','分隔开)")
    private String tags;
    @ApiModelProperty("封装查询文章的主题")
    private String theme;
    @ApiModelProperty("封装查询文章的id")
    private String articleId;
    @ApiModelProperty("封装查询文章的标题")
    private String articleTitle;
    private static class Converter implements IConverter<ArticleQueryDTO, ArticleQueryPo> {
        @Override
        public ArticleQueryPo convertToVo(ArticleQueryDTO articleQueryDTO) {
            ArticleQueryPo articleQueryPo=new ArticleQueryPo();
            String status=articleQueryDTO.getStatus();
            String tags=articleQueryDTO.getTags();
            if(!"".equals(status)&&status!=null&&!"null".equals(status)){
                articleQueryPo.setStatus(status.split(","));
            }
            if(!"".equals(tags)&&tags!=null){
                articleQueryPo.setArticleTags(tags.split(","));
                articleQueryPo.setArticleTagsLen(articleQueryPo.getArticleTags().length);
            }
            BeanUtils.copyProperties(articleQueryDTO,articleQueryPo);
            return articleQueryPo;
        }

        @Override
        public List<ArticleQueryPo> convertToVO(List<ArticleQueryDTO> t) {
            return null;
        }
    }
    /**
     * 描述：将DTO  转换为PO
     * @author 崔杰翔
     * @Date 2021/9/20 22:33
     * @return
     */
    public ArticleQueryPo   toArticleQueryPo(){
        return new Converter().convertToVo(this);
    }
}
